package com.weichen.studentgameexchange.comment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weichen.studentgameexchange.comment.entity.CommentAuditLog;
import com.weichen.studentgameexchange.comment.service.ICommentAuditLogService;
import com.weichen.studentgameexchange.common.common.Result;
import com.weichen.studentgameexchange.common.exception.ServiceException;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 惟尘
 * @since 2025-02-05
 */
@RestController
@RequestMapping("/comment/commentAuditLog")
public class CommentAuditLogController {

    @Autowired
    ICommentAuditLogService commentAuditLogService;

/**
 * TODO 管理员-评论管理--评论审核日志
 */
    /**
     * 管理员新增审核日志
     *
     * @param commentAuditLog
     * @return
     */
    @Operation(summary = "管理员新增审核日志接口")
    @PostMapping("/admin/add")
    public Result adminAdd(@RequestBody CommentAuditLog commentAuditLog) {
        return commentAuditLogService.adminAdd(commentAuditLog);
    }

    /**
     * 管理员查看单个评论审核日志
     * @param commentId
     * @return
     */
    @Operation(summary = "管理员查看单个评论审核日志接口")
    @GetMapping("/admin/selectOne/{commentId}")
    public Result adminSelectOne(@PathVariable("commentId") Long commentId){
        CommentAuditLog commentAuditLog = commentAuditLogService.adminSelectOne(commentId);
        return Result.success(commentAuditLog);
    }

    /**
     * 管理员审核评论状态
     */
    @Operation(summary = "管理员审核评论状态接口")
    @PostMapping("/admin/audite")
    public Result adminAudite(@RequestBody CommentAuditLog commentAuditLog){
        commentAuditLogService.adminAudite(commentAuditLog);
        return Result.success();
    }

    /**
     * 管理员分页查询评论信息
     *
     * @param keyword
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "管理员分页查询评论信息接口")
    @GetMapping("/admin/page")
    public Result adminPage(@RequestParam("keyword") String keyword,
                            @RequestParam(value = "page", defaultValue = "1") Integer page,
                            @RequestParam(value = "size", defaultValue = "5") Integer size) {
        Page<CommentAuditLog> commentAuditLogPage = commentAuditLogService.adminPage(keyword, page, size);
        return Result.success(commentAuditLogPage);
    }

    /**
     * 管理员修改评论审核状态
     * @param commentAuditLog
     * @return
     */
    @Operation(summary = "管理员修改评论审核状态接口")
    @PutMapping("/admin/update")
    public Result adminUpadte(@RequestBody CommentAuditLog commentAuditLog){
        commentAuditLogService.adminUpadte(commentAuditLog);
        return Result.success();
    }

    /**
     * 管理员删除单个评论审核日志
     *
     * @param auditId
     * @return
     */
    @Operation(summary = "管理员删除单个评论审核日志接口")
    @DeleteMapping("/admin/delete/{auditId}")
    public Result adminDeleteOne(@PathVariable("auditId") Long auditId) {
        if (commentAuditLogService.getById(auditId) == null)
            throw new ServiceException("审核日志不存在！");
        commentAuditLogService.removeById(auditId);
        return Result.success();
    }

    /**
     * 管理员批量删除多个评论审核日志
     *
     * @return
     */
    @Operation(summary = "管理员批量删除多个评论审核日志接口")
    @DeleteMapping("/admin/delete/batch")
    public Result adminDeleteBatch(@RequestBody List<Long> auditIds) {
        auditIds.forEach(this::adminDeleteOne);
        return Result.success();
    }
}
